package com.liang.socket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //找码头
        DatagramSocket ds = new DatagramSocket(10000);

        byte[] bytes = new byte[1024];
        //接收打包数据
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);

        //接收数据
        System.out.println("------接受前------");
        ds.receive(dp);
        System.out.println("------接受后------");
        byte[] data = dp.getData();
        int length = dp.getLength();


        //打印数据

        System.out.println(new String(bytes,0,length));

        //关闭数据
        ds.close();
    }
}
